package com.rockcent.mall.controller;

import com.rockcent.common.common.JsonResult;
import com.rockcent.common.common.RestDoing;
import com.rockcent.common.controller.BaseController;
import com.rockcent.mall.Routes;
import com.rockcent.mall.lib.domain.MallLogistics;
import com.rockcent.mall.lib.repository.MallLogisticsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by DK on 16/10/27.
 * 物流公司管理
 */
@RestController
public class MallLogisticsController extends BaseController{
    private final Logger log = LoggerFactory.getLogger(MallLogisticsController.class);

    @Autowired
    private MallLogisticsRepository mallLogisticsRepository;

    /**
     * @api {get} /mall/logistics/company/list 物流公司 列表
     * @apiGroup MALL_LOGISTICS
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiSuccess {Long} id 物流公司ID
     * @apiSuccess {String} name 物流公司名称
     * @apiSuccess {String} logisticsCode 物流公司编码
     * @apiSuccessExample {json} Success-Response:
     * {
     * "code": "1",
     * "desc": "成功"
     * "data":{
     *      "id": 71,
     *      "name": "顺丰",
     *      "logisticsCode": "shunfeng"
     *  },
     *  .....
     * }
     */
    @RequestMapping(value = Routes.MALL_LOGISTICS_COMPANY_LIST, method = RequestMethod.GET)
    public JsonResult mallLogisticsCompanyList(HttpServletRequest request){
        RestDoing doing = jsonResult -> {
            List<MallLogistics> mallLogisticsList = mallLogisticsRepository.findAll();
            jsonResult.data = mallLogisticsList;
        };
        return doing.go(request, log);
    }
}
